from django import forms
from django.template import Context, Template
from django.template.loader import get_template

from pypsqueak.group.models import Group, Assignment

class GroupAssignmentChoiceWidget(forms.Select):
	""" Field for choosing an assignment, sorted nicely by groups. """
	
	class Media:
		css= {
			'all': (
				"/files/lib/jquery/css/base/ui.all.css",
				"/files/lib/jquery/css/base/ui.accordion.css",
				)
			}
		js = (
			"/files/lib/jquery/js/jquery-1.3.2.min.js",
			"/files/lib/jquery/js/ui.core.js",
			"/files/lib/jquery/js/ui.accordion.js",
			);
	
	
	def render(self, name, value, attrs=None):
		output = super( GroupAssignmentChoiceWidget, self ).render(name, value, attrs)
		
		t = get_template('group/GroupAssignmentChoiceWidget.html')
		c = Context({'groups':Group.objects.all()})
		return t.render( c )
